﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ASmile.Extend
{
    public static class NumberExtend
    {
        public static string NumToString(long src, int minLen)
        {
            StringBuilder sb = new StringBuilder();
            for (long i = 0; i < minLen; i++)
            {
                sb.Append("0");
            }
            return src.ToString(sb.ToString());
        }

        public static string ToString(this int src, int minLen)
        {
            return NumToString(src, minLen);
        }

        public static string ToString(this long src, int minLen)
        {
            return NumToString(src, minLen);
        }

        public static string ToString(this decimal src, int minLen)
        {
            return NumToString((long)src, minLen);
        }

        public static string ToString(this float src, int minLen)
        {
            return NumToString((long)src, minLen);
        }

        static string[] ChineseNumber = new[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
        /// <summary>
        /// 仅支持100以下 2024.3.7
        /// </summary>
        public static string ToChinaWord(this int num)
        {
            int a = num / 10;
            if (a == 0)
            {
                return $"{ChineseNumber[num]}";
            }
            else if (a == 1)
            {
                int b = num % 10;
                if (b == 0)
                {
                    return $"{ChineseNumber[10]}";
                }
                else
                {
                    return $"{ChineseNumber[10]}{ChineseNumber[num % 10]}";
                }
            }
            else
            {
                int b = num % 10;
                if (b == 0)
                {
                    return $"{ChineseNumber[a]}{ChineseNumber[10]}";
                }
                else
                {
                    return $"{ChineseNumber[a]}{ChineseNumber[10]}{ChineseNumber[num % 10]}";
                }
            }
        }
    }
}
